<?php
	require("../include/connectdb.php");
	$type=$_GET['type'];
	$s=null;
	$s1=null;
	switch($type){
		case 'dm': 
			$s="domain";
			$s1="Domain";
			break;
		case 'pm': 
			$s="phanmem";
			$s1="Phần mềm";
			break;
		case 't2': 
			$s="tintuc";
			$s1="Tin tức";
			break;
		case 'tv': 
			$s="tuvan";
			$s1="Tư vấn";
			break;
		case 'w': 
			$s="web";
			$s1="Web";
			break;
		case 'dv': 
			$s="dichvu";
			$s1="Dịch vụ";
			break;					
	}
	
	//Phan trang
	$records=10;	
	$sql="select * from ".$s." where 1=1";
	if(isSet($_GET['kind'])){
		$k=$_GET['kind'];
		$sql=$sql." and ".$type."Status=".$_GET['kind'];
	}
	$res=mysql_query($sql);
	$totalpage =ceil( mysql_num_rows($res) / $records);
	$page=isSet($_GET['p'])?$_GET['p']:1;
	if(!$page||$page<=0||$page>$totalpage){ 
	$page=1;
	}
	$from=($page-1)*$records;
	$sql=$sql." order by ".$type."Id DESC limit ".$from.",".$records;
	$res=mysql_query($sql);
?>
<div class="top-bar">
	<a href="main.php?page=aart&type=<?php echo $type;?>" class="button">ADD NEW </a>
	<h1><?php echo $s1;?></h1>
	<div class="breadcrumbs"><a href="#">Homepage</a> /<a href="#"><?php echo $s1;?></a></div>
</div><br />
<div class="select-bar">
    <label>
	    <input type="text" name="textfield" />
    </label>
    <label>
		<input type="submit" name="Submit" value="Search" />
	</label>
	&nbsp;
	&nbsp;
	&nbsp;
	&nbsp;
	&nbsp;
	<?php
		switch($type){
			case 'w': ?>
				<label><a href="main.php?page=lart&type=w&kind=1">TM-DT</a></label>
				&nbsp;
				&nbsp;
				&nbsp;
				<label><a href="main.php?page=lart&type=w&kind=2">Mua bán</a></label>
				&nbsp;
				&nbsp;
				&nbsp;
				<label><a href="main.php?page=lart&type=w&kind=3">Doanh nghiệp</a></label>
				&nbsp;
				&nbsp;
				&nbsp;
				<label><a href="main.php?page=lart&type=w&kind=4">Yêu cầu</a></label>
				<?php
				break;
			case 'dm': ?>
				<label><a href="main.php?page=lart&type=dm&kind=1">Domain</a></label>
				&nbsp;
				&nbsp;
				&nbsp;
				<label><a href="main.php?page=lart&type=dm&kind=2">Hosting</a></label>
			<?php	
				break;
			case 'pm': ?>
				<label><a href="main.php?page=lart&type=pm&kind=1">PC</a></label>
				&nbsp;
				&nbsp;
				&nbsp;
				<label><a href="main.php?page=lart&type=pm&kind=2">Mobile</a></label>
				
			<?php
				break;
		}
	?>
	
</div>
<div class="contentWrapper">
<?php
	while($r=mysql_fetch_array($res)){
	$ID=$r[$type.'Id'];
?>
	<div class="perArt">
		<p class="titleArt"><?php echo substr($r[$type.'Title'],0,70);?> </p>
		<div class="detailArt"><?php echo substr($r[$type.'Detail'],4,150);?></div>
		<div align="right">
		<a href="#">Chi tiết</a>
		&nbsp;&nbsp;
		<a href="main.php?page=eart&type=<?php echo $type; ?>&ID=<?php echo $ID; ?>">Sửa</a>
		&nbsp;&nbsp;
		<a href="include/articlesProc.php?type=<?php echo $type;?>&act=del&ID=<?php echo $ID;?>">Xóa</a>
		</div>
	</div>
<?php
	}
?>
<br>
<br>
<div class="select">
	<strong>Other Pages: </strong>
	<select onChange="location.href='main.php?page=lart<?php if(isSet($k)) echo "&kind=".$k; ?>&type=<?php echo $type; ?>&p='+this.value" >
		<?php
			for($i=1;$i<=$totalpage;$i++){
		?>
		<option value="<?php echo $i; ?>" <?php if($i==$page) echo "selected"; ?> ><?php echo $i; ?></option>
		<?php
			}
		?>
	</select>
</div> 
</div>
